#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read<int>()
#define inn read<ll>()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

template<typename T>
T read(){
	T x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 5e4+10;

int cnt,h[N],n,m,x,y;
ll t[65],ins[N],w;
bool vis[N];

struct edge{int v;ll w;int nxt;}e[N<<2];
void link(int x,int y,ll w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

void insert(ll x){
	for(int i = 62;~i;i--)
		if(x >> i & 1){
			if(!t[i]) return t[i] = x,void();
			else x ^= t[i];
		}
}

ll getmax(ll x){
	for(int i = 62;~i;i--)
		if((t[i] ^ x) > x) x ^= t[i];
	return x;
}

void dfs(int x,ll p){
	vis[x] = 1; ins[x] = p;
	for(int i = h[x],y;i;i = e[i].nxt){
		if(!vis[y = e[i].v]) dfs(y,ins[x] ^ e[i].w);
		else insert(p^e[i].w^ins[y]);
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= m;i++){
		x = in,y = in,w = inn;
		link(x,y,w); link(y,x,w);
	}
	dfs(1,0);
	printf("%lld\n",getmax(ins[n]));
	return 0;
}

